<template>
  <div class="container">
    <div class="header1" style="padding: 10px 0px">
      <div style="display: flex; justify-content: space-between">
        <div style="display: flex; justify-content: start">
          <a-button class="hte-btn" @click="rePushToMdm">重新推送</a-button>
          <a-button
            v-if="userinfo.info.username == 'liangyq5'"
            style="color: red"
            class="hte-btn"
            @click="rePushToMdmByCondition()"
            >按条件全量重新</a-button
          >
          <a-button class="hte-btn" plain @click="handleReload">刷新</a-button>
        </div>
        <div style="display: flex; justify-content: end">
          <a-input-search v-model="searchForm.keyword" @search="handleToSearch" placeholder="请按照关键字进行搜索" />
          <a-button class="hte-btn del-btn" @click="showSearchForm = true">高级查询</a-button>
        </div>
      </div>
      <a-modal
        :visible="showSearchForm"
        width="70vw"
        :bodyStyle="{ padding: '10px' }"
        title="高级查询"
        @ok="handleToSearch"
        @cancel="showSearchForm = false"
      >
        <a-form-model
          ref="ruleForm"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          @keyup.enter.native="handleToSearch"
        >
          <a-row :gutter="24">
            <a-col :span="8">
              <a-form-model-item label="项目编号">
                <a-input allow-clear v-model="searchForm.projectNo" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="项目名称">
                <a-input allow-clear v-model="searchForm.projectName" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="推送状态">
                <a-select v-model="searchForm.pushToMdm" allowClear>
                  <a-select-option value=""> 全部 </a-select-option>
                  <a-select-option value="2"> 推送失败 </a-select-option>
                  <a-select-option value="1"> 推送成功 </a-select-option>
                  <a-select-option value="0"> 待推送 </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col :span="8">
              <a-form-model-item label="删除状态">
                <a-select v-model="searchForm.isDel" allowClear>
                  <a-select-option value=""> 全部 </a-select-option>
                  <a-select-option value="1"> 已删除 </a-select-option>
                  <a-select-option value="0"> 未删除 </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-modal>
    </div>
    <div class="content-list">
      <a-table
        :columns="columns"
        :data-source="records"
        rowKey="id"
        bordered
        :pagination="false"
        :customRow="customRow"
        :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      >
        <template slot="delStatusRender" slot-scope="text, record">
          <template v-if="text == 1">
            <span style="color: red">已删除</span>
          </template>
          <template v-else>
            <span style="color: green">未删除</span>
          </template>
        </template>
        <template slot="pushToMdmStatusRender" slot-scope="text, record">
          <template v-if="text == 2">
            <span style="color: red">推送失败</span>
          </template>
          <template v-else-if="text == 1">
            <span style="color: green">推送成功</span>
          </template>
          <template v-else-if="text == 0">
            <span style="color:blue">待推送</span>
          </template>
          <template v-else>
            <span style="color: grey">未定</span>
          </template>
        </template>
      </a-table>
      <a-pagination
        show-size-changer
        :default-current="1"
        :total="searchForm.total"
        @change="pageChange"
        @showSizeChange="onShowSizeChange"
        :show-total="(total) => `共 ${total} 条记录`"
      />
    </div>
  </div>
</template>
<script>
import { getAction, postAction } from '@/api/manage'
import { formatDate, parseTime } from '@/utils/util'
import { UtilsMixin } from '@/mixins/UtilsMixin'
import { TableMixin } from '@/mixins/TableMixin'
import { Modal } from 'ant-design-vue'
export default {
  mixins: [UtilsMixin, TableMixin],
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    ArticleContent: () => import('@/views/back/article/ArticleContent'),
  },
  data() {
    return {
      currUserId: this.$store.getters.userInfo.username,
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'ContractReportInfo',
      },
      urls: {
        list: '/projectBuild/searchPushToMdmPage',
        rePushToMdm: '/projectBuild/rePushToMdm',
        rePushToMdmByCondition: '/projectBuild/rePushToMdmByCondition',
      },
      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      keywordType: '1',
      json: {},
      record: {},
      records: [],
      columns: [
        {
          title: 'ID',
          dataIndex: 'id',
          width: '100px',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '项目编码',
          dataIndex: 'projectNo',
          width: '150px',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '项目名称',
          dataIndex: 'projectName',
          width: '150px',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '删除状态',
          dataIndex: 'isDel',
          width: '150px',
          align: 'center',
          ellipsis: true,
          scopedSlots: { customRender: 'delStatusRender' },
        },
        {
          title: '推送MDM状态',
          dataIndex: 'pushToMdm',
          align: 'center',
          width: '100px',
          ellipsis: true,
          scopedSlots: { customRender: 'pushToMdmStatusRender' },
        },
        {
          title: '推送时间',
          dataIndex: 'push_time',
          align: 'center',
          width: '100px',
          ellipsis: true,
        },
      ],
      showSearchForm: false,
      selectedRowKeys: [],
      selectedRows: [],
    }
  },
  async mounted() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      postAction(this.urls.list, this.searchForm).then((res) => {
        if (res.success) {
          this.records = res.result.records
          this.$set(this.searchForm, 'total', res.result.total)
        } else {
          this.$message.error('查询数据错误:' + res.message)
        }
      })
    },

    handleReload() {
      this.fetchList()
    },
    handleToSearch() {
      this.searchForm.pageNo = 1
      this.showSearchForm = false
      this.fetchList()
    },

    rePushToMdm() {
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        postAction(this.urls.rePushToMdm, this.selectedRowKeys).then((res) => {
          if (res.success) {
            this.$message.success('重置成功')
            this.fetchList()
          } else {
            this.$message.error('重置失败')
          }
        })
      }
    },
    rePushToMdmByCondition() {
      postAction(this.urls.rePushToMdmByCondition, this.searchForm).then((res) => {
        if (res.success) {
          this.$message.success('重置成功')
          this.fetchList()
        } else {
          this.$message.error('重置失败')
        }
      })
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
.container {
  .content {
    margin-top: 20px;

    section {
      margin-bottom: 18px;

      .section-table {
        .add-btn {
          margin-left: 0;
          margin-bottom: 10px;
        }

        /deep/ .a-upload__input {
          display: none !important;
        }
      }
    }
  }
}

.tips-box {
  margin-top: 32px;

  .add-btn {
    width: 180px;
    height: 40px;
    line-height: 40px;
    background-color: #4095e4;
    border-radius: 2px;
  }
}
/deep/ .el-upload__input {
  display: none !important;
}
</style>
